package com.dinzeer.slashblade_project_slr.sa.slr002;

import com.dinzeer.legendreliclib.lib.util.WaitingTick;
import com.dinzeer.legendreliclib.lib.util.slashblade.SlashBladeUtil;
import com.dinzeer.slashblade_project_slr.entity.TheSlashStringEntity;
import com.dinzeer.slashblade_project_slr.item.ItemSLRSlashBlade;
import com.dinzeer.slashblade_project_slr.regsiter.SLREntityRegsitry;
import mods.flammpfeil.slashblade.capability.slashblade.ISlashBladeState;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.level.Level;

import java.awt.*;
import java.util.Random;

public class SLR002SA {
    public static void doSlash(LivingEntity entityIn) {
        ISlashBladeState state = SlashBladeUtil.getState(entityIn.getMainHandItem());
        Level worldIn = entityIn.level();
        Random random = new Random();

        for (int i = 0; i < 50; i++) {
            int finalI = i;
            WaitingTick.schedule(i, () -> {
                if (state.getProudSoulCount()>1000){
                double angle = random.nextDouble() * 2 * Math.PI;
                double radius = random.nextDouble() * 5.0;
                double xOffset = radius * Math.cos(angle);
                double zOffset = radius * Math.sin(angle);
                double heightOffset = (Math.random() * 4.0) - 2.0;
                TheSlashStringEntity entity =
                        new TheSlashStringEntity(SLREntityRegsitry.TheSlashString.get(), worldIn);
                entity.setPos(
                        entityIn.getX() + xOffset,
                        entityIn.getY() + 1+heightOffset,
                        entityIn.getZ() + zOffset
                );

                // 随机选择颜色
                int colorType = random.nextInt(2);
                switch (colorType) {
                    case 0:
                        entity.setColor(state.getColorCode());
                        break;
                    case 1:
                        entity.setColor(13487565);
                        break;
                }
                entity.setLifetime(80- finalI);
                entity.setOwner(entityIn);
                entity.setDamage(state.getBaseAttackModifier()*0.38f);

                worldIn.addFreshEntity(entity);
                state.setProudSoulCount(state.getProudSoulCount()-1000);
                }
            });
        }
    }
  
}